package com.example.waggerdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class swaggerConfig {
    @Bean
   public Docket docket(Environment environment){
        /*只希望swagger在开发环境(dev)中使用*/
        Profiles profiles=Profiles.of("dev","test");
        boolean b= environment.acceptsProfiles(profiles);

        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .enable(b)

                .groupName("会飞的小鱼儿")
                .select()
                /*RequestHandlerSelectors 配置接口方式
                basePackage 指定扫描的包
                any 全部
                none 不扫描
                withClassAnnotation()   扫描类上的注解，参数是一个注解的反射对象
                withMethodAnnotation()  扫描方法上的注解*/
                .apis(RequestHandlerSelectors.basePackage("com.example.waggerdemo"))
                .paths(PathSelectors.any())
                .build();
    }

    private  ApiInfo apiInfo(){
        Contact contact=new Contact("会飞的小鱼儿","https://gitee.com/xye525","525371020@qq.com");
        return new ApiInfo(
                "swagger-AIP文档",
                "swagger-AIP接口描述",
                "1.0",
                "https://www.baidu.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses",
                new ArrayList<>()
        );
    }
}
